package sample.controller.todo;

import java.util.logging.Logger;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.StringUtil;

import sample.controller.meta.TodoMeta;
import sample.controller.model.Todo;

import com.google.appengine.api.datastore.KeyFactory;

public class UpdateController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(UpdateController.class.getName());

    @Override
    public Navigation run() {
        String key = asString("key");
        if (!StringUtil.isEmpty(key)) {
            TodoMeta tm = new TodoMeta();
            Todo todo = Datastore.get(tm, KeyFactory.stringToKey(key));
            todo.setContent(asString("content"));
            Datastore.put(todo);
        }
        return redirect(basePath);
    }
}
